package com.mf.dao.impl;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.mf.common.dao.impl.BaseDaoImpl;
import com.mf.dao.EslesmeDAO;
import com.mf.model.Eslesme;

@Repository
public class EslesmeDAOImpl extends BaseDaoImpl implements EslesmeDAO {

	@Autowired
	SessionFactory sessionFactory;

	public List<Eslesme> getEslesmeListByFromId(int id) {
		Criteria criteria = sessionFactory.openSession().createCriteria(Eslesme.class);
		// criteria.setFetchMode("from", FetchMode.JOIN);
		// criteria.createAlias("from", "from");
		// criteria.add(Restrictions.eq("from.id", id));
		return criteria.list();
	}

	public List<Eslesme> getEslesmeListByToId(int id) {
		Criteria criteria = sessionFactory.openSession().createCriteria(Eslesme.class);
		// criteria.setFetchMode("to", FetchMode.JOIN);
		// criteria.createAlias("to", "to");
		// criteria.add(Restrictions.eq("to.id", id));
		return criteria.list();
	}

	public List<Eslesme> getEslesmeList(int id) {
		Criteria criteria = sessionFactory.openSession().createCriteria(Eslesme.class);
		// criteria.setFetchMode("from", FetchMode.JOIN);
		// criteria.createAlias("from", "from");
		// criteria.setFetchMode("to", FetchMode.JOIN);
		// criteria.createAlias("to", "to");
		// criteria.add(Restrictions.or(Restrictions.eq("from.id", id), Restrictions.eq("to.id", id)));
		// criteria.add(Restrictions.eq("flag", true));
		return criteria.list();
	}
}
